package com.caocaog.market.front;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caocaog.market.annotation.IgnoreAuth;
import com.caocaog.market.entity.Serve;
import com.caocaog.market.service.ServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.GenericController;
import org.jeecg.common.system.domain.QueryRequest;
import org.jeecg.common.system.query.PageGenerator;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@Api(value = "serve", tags = ServeFrontController.TABLE_MEANING)
@RequestMapping("/api/serve")
public class ServeFrontController extends GenericController<Serve, ServeService> {

    public static final String TABLE_MEANING = "服务信息移动端API";

    private static final String LATEST = "服务信息移动端API-最新10条数据";
    @IgnoreAuth
    @ApiOperation(value = LATEST, notes = LATEST)
    @GetMapping(value = "/latestList")
    public Result<?> getLatestList(Serve serve) {
        return Result.OK(super.service.getLatestList(serve));
    }

    private static final String PAGE = "服务信息移动端API-分页查询";
    @IgnoreAuth
    @ApiOperation(value = PAGE, notes = PAGE)
    @GetMapping(value = "/list")
    public Result<?> getLatestList(Serve serve, QueryRequest queryRequest) {
        Page<Serve> page = PageGenerator.createPageSort(queryRequest);
        IPage<Serve> pageList = super.service.queryServePageByServeType(page, serve);
        return Result.OK(pageList);
    }

    private static final String SURROUNDING = "服务信息移动端API-周边服务";
    @IgnoreAuth
    @ApiOperation(value = SURROUNDING, notes = "请传入经纬度来获取周边服务")
    @GetMapping(value = "/surrounding")
    public Result<?> getSurroundingServe(@RequestParam("lat") String lat, @RequestParam("lng") String lng, @RequestParam("serveType") String serveType) {
        return Result.OK(super.service.getSurroundingServe(lat, lng, serveType));
    }

}
